//
//  MCNewMarketingAddGoodsModel.swift
//  StoreManage
//
//  Created by MC on 2018/6/27.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

class MCNewMarketingAddGoodsModel: NSObject {

    @objc var goodsId        : NSNumber = 0 //    商品id
    @objc var goodsName      : String = ""  //    商品名称
    @objc var mallStoreId    : NSNumber = 0 //    0平台 其他为自营
    @objc var navigateImg1   : String = ""  //    商品首图
    @objc var storeId        : NSNumber = 0 //    店铺id
    @objc var suggestedPrice : NSNumber = 0 //    建议售价
    @objc var isSelected     : Bool  = false//    是否选中
    
    
    @objc var lowestPrice : Int = Int.max           // 最低售价   取货品集合中最低的价格

    @objc var inventoryNum   : NSNumber = 0 //    库存数量（各个规格的总数）

    
    @objc var productList : NSArray = NSArray() {  //    货品集合
        didSet {
            
            
            var inventoryNumTemp = 0
            var lowestPriceTemp = Int.max
            
            
            
            let arrayM = NSMutableArray()
            for dict in productList {
                let product = dict as? [String:Any] ?? [:]
                
                if product.count != 0 {
                    let model = MCNewMarketingEditSKUModel()
                    model.setValuesForKeys(product)
                    arrayM.add(model)
                    
                    let salePrice = model.salePrice.intValue
                    if salePrice < lowestPriceTemp {
                        lowestPriceTemp = salePrice
                    }
                    inventoryNumTemp += model.inventoryNum.intValue
                } else {
                    let model = dict as! MCNewMarketingEditSKUModel
                    arrayM.add(model)
                    
                    let salePrice = model.salePrice.intValue
                    if salePrice < lowestPriceTemp {
                        lowestPriceTemp = salePrice
                    }
                    inventoryNumTemp += model.inventoryNum.intValue
                }
                

                
                
            }
            
            lowestPrice = lowestPriceTemp
            productList = arrayM
            inventoryNum = NSNumber.init(value: inventoryNumTemp)
        }
    }

    
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) { }
}
